<?php
/**
 * Created by PhpStorm.
 * User: superxing-cto
 * Date: 17/5/9
 * Time: 11:37
 */

namespace App\Models;

/**
 * Class Coupon
 * @package App\Models
 * @property string title
 * @property integer number 优惠券码
 * @property string method 优惠类型：discount:打折、reduce:减价
 * @property string valid_type 有效期类型
 * @property integer valid_val 有效期
 * @property boolean skill_active 是否限制服务类型
 * @property string skill_ids 限制服务id
 * @property integer order_scope 限制订单金额
 * @property integer price 优惠价格
 * @property boolean status 状态
 * @property boolean is_repeat 是否可以重复领取
 */
class Coupon extends ApplicationModel
{
    protected $fillable = [
        'title',
        'number',
        'method',
        'skill_active',
        'skill_ids',
        'order_scope',
        'price',
        'status',
        'is_repeat',
        'valid_type',
        'valid_val',
        'type',
        'send_type',
    ];

    //获取优惠券使用范围
    public function use_restriction()
    {
        if ($this->skill_active) {
            return "仅限";
        }
        return "全品类";
    }

    public function validity()
    {
        switch ($this->valid_type) {
            case 'month':
                return $this->valid_val . '个月';
            case 'day':
                return $this->valid_val . '天';
            case 'hour':
                return $this->valid_val . '小时';
            default:
                return '无';
        }
    }

    public function couponNumbers()
    {
        return $this->hasMany(CouponNumber::class);
    }
}